package com.wkq.util.span

import android.content.Context
import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.util.TypedValue
import androidx.annotation.ColorInt

/**
 *
 *@Author: wkq
 *
 *@Time: 2025/4/25 16:54
 *
 *@Desc:
 */
object SpanUtil {
    /**
     * 大小 颜色设置
     */
    fun getSizeColorSpan(
        context: Context, size: Int, @ColorInt color: Int, startStr: String?, endStr: String?
    ): SpannableString? {
        startStr?.let {
            val spannableString = SpannableString(startStr + endStr)
            val sizeInPx = TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_SP, size.toFloat(), context.resources.displayMetrics
            )
            val sizeColorSpan = SizeColorSpan(sizeInPx.toInt(), false, color)
            spannableString.setSpan(
                sizeColorSpan, 0, startStr.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            )
            return spannableString
        }
        return SpannableString("")

    }
}